import { createRouter, createWebHistory } from 'vue-router'
import Home from '@/views/Home.vue'
import Test from '@/views/Test.vue'
import Manager from '@/views/Manager.vue'
import Data from '@/views/Data.vue'
import Employee from '@/views/Employee.vue'
import Login from '@/views/Login.vue'
import Register from '@/views/Register.vue'
import Admin from '@/views/Admin.vue'
import Person from '@/views/Person.vue'
import Password from '@/views/Password.vue'
import Article from '@/views/Article.vue'
import Department from '@/views/Department.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: "/",
      redirect: 'login'
    },
    {
      path: '/manager',
      component: Manager,
      children:[
        {
          path: 'home',
          meta: { title: '主页' },
          component: Home
        },
        {
          path: 'data',
          meta: { title: '数据展示页' },
          component: Data
        },
        {
          path: 'employee',
          meta: { title: '员工信息' },
          component: Employee
        },
        {
          path: 'admin',
          meta: {title: '管理员信息'},
          component: Admin
        },
        {
          path: 'person',
          meta: {title: '个人信息'},
          component: Person
        },
        {
          path: 'password',
          meta: {title: '修改密码'},
          component: Password
        },
        {
          path: 'article',
          meta: { title: '文章信息'},
          component: Article
        },
        {
          path: 'department',
          meta: {title : '部门信息'},
          component: Department
        }
      ]
      // component: () => import('../views/AboutView.vue'),
    },
    {
      path: '/login',
      name: 'login',
      meta: {title: '登录'},
      component: Login
    },
    {
      path: '/register',
      name: 'register',
      meta: {title: '注册'},
      component: Register
    },
    { path: '/404', name: 'NotFound', meta: { title: '404找不到页面' },  component: () => import('../views/404.vue') },
    { path: '/:pathMatch(.*)', redirect: '/404' }
  ],
})
// from：将要进行跳转的当前route对象 (跳转前的一些操作)  
// to: 跳转后route对象 (跳转后的一些操作)  
// next(): 调用该方法后, 才能进入下一个钩子
router.beforeEach((to, from, next) => {
  document.title = to.meta.title; 
  next()
})
export default router
